17.3 Initialization of Different Scheduling Group Categories
The traditional Completely Fair Scheduler (CFS) utilized individual tasks or threads as the minimal scheduling granularity to facilitate proportional CPU resource sharing among processes. To prevent an individual user from exploiting this mechanism by spawning a massive number of threads to monopolize the CPU at the expense of other users, Linux implements a task-group-level resource allocation policy that can be enabled via the compilation configuration switch CONFIG_FAIR_GROUP_SCHED (Fair Group Scheduling). Under this paradigm, the system first distributes CPU time proportionally among distinct users or container control groups (cgroups), and subsequently subdivides that allocated quota equally among the threads internal to each respective group.
To prevent high-priority real-time tasks from completely starving the system of CPU cycles, Linux can restrict the aggregate execution bandwidth of real-time workloads via the compilation switch CONFIG_RT_GROUP_SCHED (Real-Time Group Scheduling).
When fair group scheduling is active, the kernel must maintain supplemental scheduling entities and runqueue pointers for each individual CPU core. Similarly, when real-time group scheduling is enabled, it must concurrently maintain dedicated real-time scheduling entities and real-time runqueue pointers for each CPU core.
The code sequence situated precisely between the execution of wait_bit_init() and the conditional block #ifdef CONFIG_CPUMASK_OFFSTACK is responsible for allocating memory and updating pointer fields for these supplemental scheduling entities and runqueues when group scheduling mechanisms are active.
The kernel maintains two distinct CPU affinity masks (cpumask) per CPU core to coordinate load balancing routines and streamline the selection of vacant processor cores. By default, these bitmasks are allocated statically on the execution stack or within static tracking structures. However, on high-core-count hardware topologies (such as architectures with 256 cores), these masks consume a significant volume of stack memory. This excessive footprint can trigger kernel stack overflows, induce high-frequency CPU cache thrashing, and lead to massive bloat within administrative data structures. To eliminate this overhead, Linux introduces the compilation switch CONFIG_CPUMASK_OFFSTACK. When CONFIG_CPUMASK_OFFSTACK is enabled, the kernel dynamic carves out the memory required for the CPU bitmasks directly from the heap. The code block wrapped inside the #ifdef CONFIG_CPUMASK_OFFSTACK directives dynamic allocates memory for each CPU on its corresponding home NUMA node. Within this logic path, kzalloc_node() executes zero-filled heap allocation bound to a specific node, while cpu_to_node(i) resolves the absolute numerical index of the NUMA node hosting the i-th CPU core.
The functions init_rt_bandwidth() and init_dl_bandwidth() initialize the global bandwidth control architectures for the Real-Time (RT) and Deadline (DL) scheduling classes, respectively, preventing errant real-time tasks from exhausting total CPU capacity and causing the operating system to hang. Within these interfaces, global_rt_period() defines the standard enforcement cycle window, and global_rt_runtime() establishes the absolute maximum continuous duration that real-time threads are permitted to execute during a single cycle. Once a real-time task group breaches this runtime budget, the scheduler forces it to suspend execution until the subsequent scheduling period commences.
If symmetric multiprocessing support is required (configured via the compilation flag CONFIG_SMP), the system instantiates a globally unique structural variable named def_root_domain (the root scheduling domain) to manage all CPU cores. The primary objective of init_defrootdomain() is to execute fundamental initialization passes on this static global instance, which includes allocating its mandatory tracking CPU masks (such as span, online, and dlo_mask) and setting the structure's refcount reference counter field to 1.
The def_root_domain structure acts as the core static infrastructure managing multi-core CPU load balancing alongside real-time and deadline scheduling policies. Its default behavioral characteristics and responsibilities manifest primarily across three functional domains:
-
Fallback CPU Container Management:
During early system bootstrap or under operational scenarios where user space has not explicitly configured localized cpuset partitions, the kernel defaults to bundling all physical CPU cores under the direct jurisdiction of the def_root_domain. -
Decision Hub for Global Scheduling Policies:
The root_domain structure encapsulates dedicated inner data tracking frameworks engineered to accelerate real-time task dispatching. For instance, the cpupri field (RT Priority Management) records the maximum priority level of the real-time tasks actively executing on each CPU within the current root domain, allowing high-priority RT threads to rapidly preempt the least occupied processor core. Concurrently, the cpudl field (Deadline Tracking Management) logs the maximum deadline timeline across the respective CPUs, which serves as the algorithmic engine required to execute global Earliest Deadline First (EDF) scheduling. -
Boundary Isolation for Load Balancing:
Linux permits the segregation of CPU cores into independent, isolated resource pools via the user-space cpuset mechanism. Under this configuration, the kernel dynamically allocates (alloc_rootdomain) fresh root domains, while the static def_root_domain serves as the baseline architectural template and initial reference state for the isolation framework.
Within the hierarchy of Linux task scheduling orchestration, tasks are grouped dynamically into multi-tiered structures. Every operational thread instantiated during the system boot sequence belongs to a master tracking domain designated as the root task group (root_task_group). The root task group acts as the direct ancestor to all subsequent group hierarchies, and all newly spawned processes initially hold membership within this group.
When real-time group scheduling is active, the function init_rt_bandwidth() is triggered to initialize the real-time bandwidth properties of the root task group. It maps the real-time enforcement cycle via global_rt_period() (defaulting to 1 second) and constrains the runtime budget limit via global_rt_runtime() (defaulting to 0.95 seconds), ensuring that real-time execution threads contained within the root group are mathematically restricted from consuming the entirety of CPU execution cycles, thereby preventing system lockups.
Linux supports resource orchestration scaling either on a task-group granularity or on an isolated process-level granularity. The compilation configuration flag CONFIG_CGROUP_SCHED enables control group scheduling, which permits processes to be aggregated into logical groups and authorizes the scheduler to allocate CPU execution times slices directly to the group container as a unified scheduling entity. If this compilation option is omitted, the scheduler falls back to allocate and dispatch execution cycles purely on an individual, per-process basis.
The structural code sequence:
task_group_cache = KMEM_CACHE(task_group, 0);
list_add(&root_task_group.list, &task_groups);
INIT_LIST_HEAD(&root_task_group.children);
INIT_LIST_HEAD(&root_task_group.siblings);
autogroup_init(&init_task);
executes the following foundational milestones:
-
Instantiating a specialized Lookaside cache named task_group within the slab allocator to facilitate high-efficiency allocation of process group tracking structures.
-
Appending the root_task_group master descriptor node directly into the global task_groups tracking chain.
-
Initializing the child list and sibling list tracking headers embedded inside the root_task_group.
Under standard CFS scheduling constraints, all processes enjoy equal scheduling weight profiles. If multiple workloads are spawned from a single terminal interface (tty)—for instance, running make -j32 to compile a kernel—the system instantiates 32 active processes. If the user simultaneously opens a web browser to navigate the interface, the browser thread can harvest only approximately $\frac{1}{33}$ of the total CPU time slice allocation, inducing severe latency lagging. To eliminate this bottleneck, Linux introduces the autogroup structural framework. Via this subsystem, the kernel automatically binds all processes originating from an identical terminal interface into a single, unified task group. Under this layout, the 32 compilation processes are aggregated together to share the budget of one unified task group, while the web browser operates inside a separate, independent task group. Consequently, both groups split the total CPU execution time equally.
The routine autogroup_init() is hosted within the source file git/kernel/sched/autogroup.c and is responsible for bootstrapping the default autogroup structural template (designated as autogroup_default). It maps the root task group pointer onto the tg (task group) field of autogroup_default, sets the baseline object reference counter to 1, and initializes an internal read-write semaphore (struct rw_semaphore) to coordinate lock synchronization passes. Finally, it establishes pointer linkages via signal metrics, formally anchoring the kernel's very first process context (the bootstrap process init_task) onto the newly initialized default automated group structure.